Post

Replies

Boosts

Views

Activity

Comment on Dateformatter with "dd-MMM-yyyy" for September month returning wrong date
I am just calculating age from string date which we receive from backend database /* Code which is not working for new version of iOS 15 */ let startDate = "01-Sep-1970" // got this date from backend let dateFormatter = DateFormatter() dateFormatter.dateFormat = "dd-MMM-yyyy" let formatedStartDate = dateFormatter.date(from: startDate) // getting nil here let currentDate = Date() let components = Set<Calendar.Component>([.second, .minute, .hour, .day, .month, .year]) let differenceOfDate = Calendar.current.dateComponents(components, from: formatedStartDate!, to: currentDate) // getting crash here let age = Double(differenceOfDate.year ?? 0) /* Code which is working for older version of iOS 12 */ let startDate = "01-Sep-1970" // got this date from backend let dateFormatter = DateFormatter() dateFormatter.dateFormat = "dd-MMM-yyyy" let formatedStartDate = dateFormatter.date(from: startDate) let currentDate = Date() let components = Set<Calendar.Component>([.second, .minute, .hour, .day, .month, .year]) let differenceOfDate = Calendar.current.dateComponents(components, from: formatedStartDate!, to: currentDate) let age = Double(differenceOfDate.year ?? 0) // getting expected value
Topic: App & System Services SubTopic: General Tags:
May ’22
Comment on Dateformatter with "dd-MMM-yyyy" for September month returning wrong date
I am just calculating age from string date which we receive from backend database /* Code which is not working for new version of iOS 15 */ let startDate = "01-Sep-1970" // got this date from backend let dateFormatter = DateFormatter() dateFormatter.dateFormat = "dd-MMM-yyyy" let formatedStartDate = dateFormatter.date(from: startDate) // getting nil here let currentDate = Date() let components = Set<Calendar.Component>([.second, .minute, .hour, .day, .month, .year]) let differenceOfDate = Calendar.current.dateComponents(components, from: formatedStartDate!, to: currentDate) // getting crash here let age = Double(differenceOfDate.year ?? 0) /* Code which is working for older version of iOS 12 */ let startDate = "01-Sep-1970" // got this date from backend let dateFormatter = DateFormatter() dateFormatter.dateFormat = "dd-MMM-yyyy" let formatedStartDate = dateFormatter.date(from: startDate) let currentDate = Date() let components = Set<Calendar.Component>([.second, .minute, .hour, .day, .month, .year]) let differenceOfDate = Calendar.current.dateComponents(components, from: formatedStartDate!, to: currentDate) let age = Double(differenceOfDate.year ?? 0) // getting expected value
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
May ’22
Comment on Dateformatter with "dd-MMM-yyyy" for September month returning wrong date
Setting the DateFormatter with local identifier as "en_US_POSIX" is returning expected value. Just for understanding, Why it got affected to only latest version of iOS all of a sudden ? i.e iOS 15.4 While it's working fine for lower version of iOS.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
May ’22
Comment on Dateformatter with "dd-MMM-yyyy" for September month returning wrong date
Looks like Apple has fix date format issue in latest version on iOS 15.5 Same old code is working fine on latest version of iOS 15.5 after update
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
May ’22
Comment on Dateformatter with "dd-MMM-yyyy" for September month returning wrong date
Looks like Apple has fix date format issue in latest version on iOS 15.5. Same old code is working fine on latest version of iOS 15.5 after update
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
May ’22
Comment on Dateformatter with "dd-MMM-yyyy" for September month returning wrong date
I have updated my code using en_US_POSIX to avoid crashes for future release.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
May ’22